/* implements message_definition.h. There are the functions used to access a message, even in a UP. We use such functions because it makes maintainance easier as the internal structure of a message can change without affecting anything else. Those functions are NOT accessed through a syscall by the UP because they act on a piece of memory owned by the process (the message). Just like the functions in string.h, they form an abstraction layer to make life easier for the programmer (and the system designer who can change the type message without worrying about breaking old programs as long as he keeps those functions up to date). */

#include "message_definition.h"

int32_t message_get_from(message_t target){
  if(target == NULL)
    return INCORRECT_REQUEST;
  return target->from;
}

int32_t message_get_to(message_t target){
  if(target == NULL)
    return INCORRECT_REQUEST;
  return target->to;
}

int8_t message_get_data_flag(message_t target){
  if(target == NULL)
    return INCORRECT_REQUEST;
  return target->data_flag;
}

int32_t message_get_priority(message_t target){
  if(target == NULL)
    return INCORRECT_REQUEST;
  return target->priority;
}

char* message_get_str_value(message_t target){
  if(target != NULL && target->data_flag == STR_DATA)
    return target->data.str_data;
  return NULL;
}

int32_t message_get_int_value(message_t target){
  if(target != NULL){
    if(target->data_flag == INT_DATA)
      return target->data.int_data;
  }
  return 0;
}

int32_t message_get_pinfo_priority_value(message_t target){
  if(target == NULL || target->data_flag != PINFO_DATA)
    return INCORRECT_REQUEST;
  return target->data.pinfo_data.priority;
}

int32_t message_get_pinfo_program_id_value(message_t target){
  if(target == NULL || target->data_flag != PINFO_DATA)
    return INCORRECT_REQUEST;
  return target->data.pinfo_data.program_id;
}

int32_t message_get_pinfo_parent_value(message_t target){
  if(target == NULL || target->data_flag != PINFO_DATA)
    return INCORRECT_REQUEST;
  return target->data.pinfo_data.parent;
}

int32_t message_get_pinfo_status_value(message_t target){
  if(target == NULL || target->data_flag != PINFO_DATA)
    return INCORRECT_REQUEST;
  return target->data.pinfo_data.status;
}
